<?php

use \GatewayWorker\Lib\Gateway;
//有意义协议
class cmd_login extends cmdbase
{
	public function onCmd($msg){
		//组装玩家id
		$user_id = ClientMgr::getUid($msg->user, $msg->psw);
		$_SESSION[SessionTag::uid] = $user_id;
 		//把在线的旧玩家踢下线
		if(Gateway::isUidOnline($user_id)){
			$client_id_list = Gateway::getClientIdByUid($user_id);
			foreach ($client_id_list as $client_id) {
				$notify_kick = new notify_kick();
				$notify_kick->msg = "login kick out";
				$message = Events::wrapMsg(notify_kick::class, $notify_kick);
				Gateway::closeClient($client_id, $message);
				echo "warning=>玩家在线，需要提下线:$client_id\n";
			}
		}

 		$client_id = $this->getCurClientId();
		//绑定用户id，方便下次踢人或者恢复现场
 		Gateway::bindUid($client_id, $user_id);

		$msg_body = new login_rsp();
		$msg_body->ret = NetErrorCode::None;
		$msg_body->reason = $user_id;

 		return $msg_body;
	}
}